<template>
  <section class="query">
    <div class="bg"></div>
    <div class="container">
      <div class="card" style="padding:16px;">
        <h1 class="title">{{ info.search_type }}</h1>
        <p style="margin:0 0 16px;color:var(--muted);">以下为本次查询的信息与结果展示</p>

      <div class="row row-2">
        <div class="field">
          <label for="user_birthday_date" class="ink-label">出生年月</label>
          <input id="user_birthday_date" :value="info.user_birthday_date" class="input" type="date" />
        </div>
        <div class="field">
          <label for="user_birthday_time" class="ink-label">出生时间</label>
          <input id="user_birthday_time" :value="info.user_birthday_time" class="input" type="time" />
        </div>
      </div>

      <div class="row">
        <div class="field">
          <label for="user_sex" class="ink-label">性别</label>
          <input id="user_sex" :value="info.user_sex" class="input" type="text" />
        </div>
      </div>

      <div class="row">
        <div class="field">
          <label for="address" class="ink-label">地址</label>
          <input id="address" :value="info.address" class="input" type="text" />
        </div>
      </div>      
      <input id="id" :value="info.id" type="hidden" />
      <div class="actions">
        <a
          class="btn big"
          :href="downloadUrl"
          target="_blank"
          rel="noopener"
          :class="{ disabled: !downloadUrl }"
        >
          <span>下载</span>
        </a>
      </div>

      <div class="card result">
        <div class="result-content">
          <h2 style="margin:0 0 8px;">查询结果</h2>
          <pre>{{ info.content }}</pre>
        </div>
      </div>
      </div>
    </div>
  </section>
</template>

<script setup>
import { ref, onMounted, watch } from 'vue'
import { useRoute } from 'vue-router'
import axios from 'axios'
import { makeUrl } from '../lib/config'

const route = useRoute();
const loading = ref(false)
const info = ref({})
const downloadUrl = ref('')
const id = String(route.query?.out_trade_no || '')

onMounted(async () => { 
  downloadUrl.value = await makeUrl(`/api/down/${encodeURIComponent(id)}/`)
  console.log(id)
    const url = await makeUrl(`/api/display/${encodeURIComponent(id)}/`)
    console.log(url)
  axios.get(url)
      .then(res => {
        const raw = res?.data ?? {}
        const data = raw?.data ?? raw
        info.value = {
          ...data,
          content: data?.content ?? data?.result?.content ?? data?.info?.content ?? ''
        }
        console.log('display info', info.value)
      })
      .catch(err => {
      alert(err?.response?.data?.message || err.message || '加载失败')
    })
})
</script>

<style scoped>
.query {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}
.bg {
  position: absolute;
  inset: 0;
  background-image: url('/images/bg.jpg');
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  filter: blur(3px) saturate(1.05) brightness(0.96);
  opacity: 0.55;
  transform: scale(1.06);
  will-change: transform;
  z-index: 0;
}
.bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.80) 0%, rgba(255,255,255,0.90) 55%, rgba(255,255,255,0.96) 100%);
}
.container { position: relative; z-index: 1; }

.ink-label {
  font-family: 'Ma Shan Zheng','Zhi Mang Xing','Long Cang','KaiTi','STKaiti','SimSun',sans-serif;
  color: #0f172a;
  font-weight: 700;
  margin-bottom: 6px;
}

/* 统一各行间距与字段布局 */
.row {
  display: flex;
  gap: 12px;
  margin: 12px 0;
}
.row .field { flex: 1; }
.row-2 .field { flex: 1; }
.field { display: flex; flex-direction: column; }

.actions {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}
.btn.big {
  font-size: 18px;
  padding: 14px 24px;
  min-width: 180px;
  border-radius: 999px;
  text-decoration: none;
}
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
}
.loading-inline { display: inline-flex; align-items: center; gap: 8px; }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(14,165,233,.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result { margin-top: 16px; }
.result-content { padding: 12px 16px; }
.result-content pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
.result-content.clipped {
  max-height: 260px;
  overflow: hidden;
  position: relative;
}
.result-content.clipped::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 80px;
  background: linear-gradient(to bottom, rgba(255,255,255,0), #fff);
}
.pay-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 16px;
}
.pay-btn { background: #111; }
.pay-tip { margin: 0; color: var(--muted); font-size: 13px; }

/* —— 道家玄学风格增强 —— */
.title {
  margin: 0 0 8px;
  font-family: 'Ma Shan Zheng','Zhi Mang Xing','Long Cang','KaiTi','STKaiti',serif;
  color: #3a2a1a;
  letter-spacing: 2px;
  font-size: 28px;
}
.card {
  background: #fff8e9;
  border-radius: 16px;
  border: 1px solid rgba(58,42,26,0.25);
  box-shadow: 0 10px 30px rgba(58,42,26,.12);
  position: relative;
}
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0, transparent 10px, rgba(0,0,0,0.02) 11px),
              radial-gradient(circle at 20% 10%, rgba(221,190,117,.12), transparent 60%),
              radial-gradient(circle at 80% 90%, rgba(221,190,117,.08), transparent 60%);
  border-radius: 16px;
}
.input, .select {
  background: #fffdf7;
  border: 1px solid rgba(58,42,26,0.25);
}
.actions .btn.big {
  background: linear-gradient(180deg, #e7c96a, #d4af37);
  color: #2b1c12;
  box-shadow: 0 6px 16px rgba(212,175,55,.35);
}
.pay-btn { background: #2b1c12; }
.tip { color: #8b5e34; }
</style>